package net.oschina.esb.webmvc.exception;

import net.oschina.esb.webmvc.exception.handler.ExceptionViewResolver;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

import java.util.List;

/**
 * 自定义异常处理
 *
 * @author Arvin
 * @time 2017/12/6 9:15
 */
@AutoConfigureBefore(ErrorMvcAutoConfiguration.class)
@ConditionalOnMissingBean(ErrorAttributes.class)
@Import(AutoWebmvcExceptionSpringBootRegister.class)
public class AutoWebmvcExceptionConfiguration {

    @Bean
    @ConditionalOnMissingBean(value = ErrorAttributes.class, search = SearchStrategy.CURRENT)
    public ExtendErrorAttributes errorAttributes(List<ExceptionViewResolver> exceptionViewResolverList) {
        return new ExtendErrorAttributes(exceptionViewResolverList);
    }

}
